// pages/goodsClassify/goodsClassify.js
import {
	shareOptions
} from "../../utils/access";
import request from "../../utils/request";
const api = require("../../config/api");


Page({

  /**
   * 页面的初始数据
   */
  data: {
    sendTabIndex:0,
    sendTabActive:0,
    classifyList: [],
    classifySubList: [],
    classifySubId:0,
    title:"",
  },

  handleTab(e){
    const val=e.currentTarget.dataset.index;
    let arrs=[];
    arrs=this.data.classifyList[val].list
    this.setData({
      sendTabIndex: val,
      sendTabActive: this.data.classifyList[val].id,
      classifySubList:arrs,
      title:this.data.classifyList[val].name,
    });
  },
  goGoodsSearch(){
    wx.navigateTo({
			url: '/pages/goodsSearch/goodsSearch',
		})
  },
  goGoodsSubClassify(e){
    const val=e.currentTarget.dataset.index;
    if (val!=0) {
      this.setData({
        title:this.data.classifySubList[val].name,
      });
    }
    wx.navigateTo({
      url: `/pages/goodsSubClassify/goodsSubClassify?goodsClassifyId=${this.data.sendTabActive}&goodsSubClassifyId=${this.data.classifySubList[val].id}&title=${this.data.title}`,
    })
  },
//获取商品列表
async getClassifyList() {
  const res = await request.get(api.classifyList, {});
    this.setData({
      classifyList: res.data,
      classifySubList:res.data[0].list,
      sendTabIndex: 0,
      sendTabActive:res.data[0].id,
      title:res.data[0].name,
    });
},
  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
		this.getClassifyList();
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage(e) {
    return shareOptions('default', e)
  }
})